<!--学生选报校外题目-->
<style>
	.dq {
		text-align: left;
		padding-top: 20px;
		font-size: 16px;
	}
	
	.dq span {
		font-size: 16px;
	}
	
	.dq a {
		display: inline-block;
		color: black;
		text-decoration: none;
	}
	
	.input-group {
		margin-bottom: 20px;
	}
	
	.bottom_10 {
		margin-bottom: 20px;
	}
	
	#content {
		height: 240px;
	}
</style>

<h3 class="bottom_10">校外毕设选题</h3>
<div class="input-group">
	<span class="input-group-addon" id="basic-addon2">毕设题目</span>
	<input id="out_topic" type="text" class="form-control" placeholder="请填写毕设题目" aria-describedby="basic-addon2" required>
</div>
<div class="input-group">
	<span class="input-group-addon" id="basic-addon4">毕设描述</span>
	<textarea class="form-control" type="text" id="content" placeholder="请填写毕设描述" aria-describedby="basic-addon4" required></textarea>
</div>
<div class="input-group">
	<span class="input-group-addon" id="basic-addon3">指导老师</span>
	<select id="teacher_name" class="form-control" aria-describedby="basic-addon3">

	</select>
</div>
<button type="button" class="btn btn-primary " id="xuanze" style="float: right;">提交选题</button>

<!-- 提交成功或者失败的时候弹出的模态框 -->
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
	<div class="modal-dialog modal-sm" role="document">
		<div class="modal-content">
			...
		</div>
	</div>
</div>

<script>
	$.ajax({ //已进入就加载好老师的下拉列表
		xhrFields: {
			withCredentials: true
		},
		type: 'get',
		url: getFullURL('user/get-ter'),
		data: {},
		dataType: 'json',
		success: function(data) {
			// var  data  =  jQuery.parseJSON(obj);
			console.log(data)
			if(data.status == 0) {
				$.each(data.teacher, function(i, n) {
					var teacher_name = `<option value="` + n.tno + `">` + n.name + `</option>`
					$('#teacher_name').append(teacher_name)
				})
			}
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})

	function put_gid() {
		$.ajax({ //选题的ajax
			xhrFields: {
				withCredentials: true
			},
			type: 'post',
			url: getFullURL('user/sub-outtc'),
			data: {
				topic: $('#out_topic').val(),
				content: $('#content').val(),
				tno: $('#teacher_name').val()
			},
			dataType: 'json',
			success: function(data) {
				// var  data  =  jQuery.parseJSON(obj);
				console.log(data)
				if(data.status == 0) {
					alert('提交成功！');
					$('.center').html('');
					$('.center').load('./studentlook.html');
				} else {
					alert('提交失败，请重新提交！')
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	function get_cost() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('user/get-cost'),
			data: {},
			dataType: 'json',
			success: function(data) {
				if(data.status == 0) {
					if(data.cost == 0) {
						put_gid()
					} else {
						alert("您的学费未缴纳完毕，请联系相关老师核查！");
						return;
					}
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	$('#xuanze').click(function() {

		if($('#out_topic').val() == null || $('#out_topic').val() == "") {
			alert("毕设题目不能为空！");
			return;
		} else if($('#content').val() == null || $('#content').val() == "") {
			alert("毕设描述不能为空！");
			return;
		}

		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('user/bstp-status'),
			data: {},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.bsStatus == -1 || data.bsStatus == 0) {
					get_cost()
				} else {
					alert('您已选报成功，请查看审核状态！')
					$('.center').html('');
					$('.center').load('./studentlook.html');
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})
</script>